#include <iostream>
#include <sstream>
#include <SFML/Graphics/RenderWindow.hpp>
#include <nice2d/macros.h>
#include <nice2d/application.h>
#include <nice2d/text.h>
#include <nice2d/scene.h>
#include <nice2d/background.h>
#include <nice2d/components/fps.h>
#include <nice2d/components/fontmanager.h>

class UnitScene : public Scene
{
public:
    void onInitialed()override
    {
        setBackground(Background::create(sf::Color::Green));
        setSceneBox({0.0f, 0.0f, 800.0f, 600.0f});

        fps = GET_APPLICATION_COMPONENT(Fps);

        text = std::make_shared<Text>();
        text->setCharacterSize(16);
        text->setTextColor(sf::Color::Black);
        text->setBackgroundColor(sf::Color::Transparent);
        text->setFont("./../data/font/arial.ttf");
        text->setText("nice2d");
        text->setPosition(6, 6);
        addChild(text);
    }

    void onUpdateScene(float deltaTime) override
    {
        (void)deltaTime;

        std::stringstream stream;
        stream.precision(4);

        stream << fps->getFps();

        static const std::string fpsString = "fps:";
        text->setText(fpsString + stream.str());
    }
private:
    std::shared_ptr<Fps> fps;
    std::shared_ptr<Text> text;
};

DECLARE_MAIN_FUNCTION_WITH_SCENE(800, 600, "unit05", UnitScene)
